// src/utils/roomInitializer.ts
import { Server, matchMaker } from 'colyseus';
import { XingXiuCunRoom } from '../rooms/XingXiuCunRoom';
import { XingXiuCunDongRoom } from '../rooms/XingXiuCunDongRoom';

/**
 * 需要预创建的地图房间列表
 */
const MAP_ROOMS = [
    { name: "XingXiuCun", class: XingXiuCunRoom },
    { name: "XingXiuCunDong", class: XingXiuCunDongRoom },
];

export async function initializeRooms(gameServer: Server) {
    for (const { name, class: RoomClass } of MAP_ROOMS) {
        // 1. 注册房间类型
        gameServer.define(name, RoomClass).enableRealtimeListing();
        console.log(`✅ 已注册房间类型: ${name}`);

        // 2. 预先创建一个实例
        const room = await matchMaker.createRoom(name, {});
        console.log(`✅ 已创建房间实例: ${name} (roomId: ${room.roomId})`);
    }
}
